package cn.jorian.framework.util;

import java.security.SecureRandom;
import java.util.UUID;

public class AppKeySecretGeneratorUtil {

    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    private static final int SECRET_LENGTH = 32;

    /**
     * app key
     * @return
     */
    public static String generateAppKey() {
        return UUID.randomUUID().toString();
    }

    /**
     * app secret
     * @return
     */
    public static String generateAppSecret() {
        SecureRandom random = new SecureRandom();
        StringBuilder secret = new StringBuilder(SECRET_LENGTH);
        for (int i = 0; i < SECRET_LENGTH; i++) {
            secret.append(CHARACTERS.charAt(random.nextInt(CHARACTERS.length())));
        }
        return secret.toString();
    }
}